//返回年月日
function add0(m){ 
    return m<10?'0'+m:m
 };
// 格式化时间戳
export function getFormatTime(shijianchuo) {
    let time = new Date(shijianchuo);
    let y = time.getFullYear();
    let m = time.getMonth() + 1;
    let d = time.getDate();
    let h = time.getHours();
    let mm = time.getMinutes();
    let s = time.getSeconds();
    return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
}


// 格式化业务类新型
export function businessType(businessType) {
    if (businessType == 0) {
        return '其它';
    } else if (businessType == 1) {
        return '新增';
    } else if (businessType == 2) {
        return '修改';
    } else if (businessType == 3) {
        return '删除';
    } else if (businessType == 4) {
        return '授权';
    } else if (businessType == 5) {
        return '导出';
    } else if (businessType == 6) {
        return '导入';
    } else if (businessType == 7) {
        return '强退';
    } else if (businessType == 8) {
        return '生成代码';
    } else if (businessType == 9) {
        return '清空数据';
    } else if (businessType == 10) {
        return '控制操作';
    } else {
        return '';
    }
}

// 获取返回参数
export function getRuturnResult(JSONResult) {
    let toJSON = JSON.parse(JSONResult);
    return toJSON.msg;
}

// 过滤操作方法
export function getMethod(methodAll) {
    let newStringMethod = '';
    let test = methodAll;
	let methodName = test.split('.');
	if (methodName.length>4) {
		for (let i= 3; i<methodName.length; i++) {
			newStringMethod += methodName[i]+".";
		}
    } else {
        return methodAll(0, newStringMethod.length-2);
    }
	return newStringMethod.substring(0, newStringMethod.length-3);
}


// 是否是数组
function isArray(value) {
    return (value instanceof Array);
}
// 是否是数字
function isNumber(value) {
    return (!isNaN(value));
}
// 是否是字符串
function isString(value) {
    return (typeof(value)=='string');
}
// 是否是boolean值
function isBool(value) {
    return (typeof(value)=="boolean");
}
// 是否是基本数据类型
function isFundamentalType(value) {
    return (isNumber(value) || isString(value) || isBool(value));
}


// 请求参数     (递归不会写)
export function getOperParam(value) {
    if (value==null) {
        return '登录超时，没有记录用户操作';
    }
    let result = [];
    if (isArray(value)) { // 数组类型
        value.forEach(e1 => {
            if (isArray(e1)) {

                let e1Children = [];
                let e1Self = {label: "数组", children: e1Children};
                e1.forEach(e2=> {
                    if (isFundamentalType(e2)) {
                        e1Children.push({label: e2})
                    } else {
                        for (let e2Key in e2) {
                            let getE2Value = e2[e2Key];
                            e1Children.push({label: e2Key + ': ' + getE2Value});
                        }
                    }
                })
                result.push(e1Self);

            } else if (isFundamentalType(e1)) {

                result.push({label: "单独的数据： "+e1});

            } else {

                for (let e1Key in e1) {
                    let getE1Value = e1[e1Key];
                    if (isArray(getE1Value)) {
                        let e1Children = [];
                        let e1Self = {label: "数组", children: e1Children};
                        getE1Value.forEach(e2=> {
                            if (isArray(e2)) {
                                e2.forEach(e3=>{
                                    e1Children.push({label: "单独的数字： "+e3})
                                })
                            } else if (isFundamentalType(getE1Value)) {
                                e1Children.push({label: "单独的数字： "+getE1Value})
                            } else {
                                for (let selfKey in getE1Value) {
                                    let getKeyValue = getE1Value[selfKey];
                                    e1Children.push({label: selfKey+": "+getKeyValue})
                                }
                            }
                        })
                        result.push(e1Self);

                    } else if (isFundamentalType(getE1Value)) {
                        result.push({label: e1Key+"： "+getE1Value});
                    } else {
                        for (let selfKey in getE1Value) {
                            let getKeyValue1 = getE1Value[selfKey];
                            if (isArray(getKeyValue1)) {

                                let e1Children = [];
                                let e1Self = {label: "数组", children: e1Children};
                                getKeyValue1.forEach(e3=>{
                                    e1Children.push({label: "单独的数据： "+e3})
                                })
                                result.push(e1Self);

                            } else if (isFundamentalType(getKeyValue1)) {
                                result.push({label: selfKey+"： "+getKeyValue1})
                            } else {
                                let e1Children = [];
                                let e1Self = {label: selfKey, children: e1Children};
                                for (let selfKey2 in getKeyValue1) {
                                    let getKeyValue2 = getKeyValue1[selfKey2];
                                    e1Children.push({label: selfKey2+": "+getKeyValue2})
                                }
                                result.push(e1Self);
                            }
                        }
                    }
                }
            }
        });

    } else if (isFundamentalType(value)) { // 数组基本数据类型单独的数据：
        result.push({label: "单独的数据： "+value});

    } else {
        for (let selfKey in value) {
            let e1 = value[selfKey];
            if (isArray(e1)) {

                let e1Children = [];
                let e1Self = {label: "数组", children: e1Children};
                e1.forEach(e2=> {
                    if (isFundamentalType(e2)) {
                        e1Children.push({label: "单独的数据： "+e2})
                    } else {
                        for (let e2Key in e2) {
                            let getE2Value = e2[e2Key];
                            e1Children.push({label: e2Key + ': ' + getE2Value});
                        }
                    }
                })
                result.push(e1Self);

            } else if (isFundamentalType(e1)) {

                result.push({label: selfKey+": "+e1});

            } else {

                for (let e1Key in e1) {
                    let getE1Value = e1[e1Key];
                    if (isArray(getE1Value)) {
                        let e1Children = [];
                        let e1Self = {label: "数组", children: e1Children};
                        getE1Value.forEach(e2=> {
                            if (isArray(e2)) {
                                e2.forEach(e3=>{
                                    e1Children.push({label: "单独的数据： "+e3})
                                })
                            } else if (isFundamentalType(getE1Value)) {
                                e1Children.push({label: e1Key+"： "+getE1Value})
                            } else {
                                for (let selfKey in getE1Value) {
                                    let getKeyValue = getE1Value[selfKey];
                                    e1Children.push({label: selfKey+": "+getKeyValue})
                                }
                            }
                        })
                        result.push(e1Self);

                    } else if (isFundamentalType(getE1Value)) {
                        result.push({label: getE1Value});
                    } else {
                        for (let selfKey in getE1Value) {
                            let getKeyValue1 = getE1Value[selfKey];
                            if (isArray(getKeyValue1)) {

                                let e1Children = [];
                                let e1Self = {label: "数组", children: e1Children};
                                getKeyValue1.forEach(e3=>{
                                    e1Children.push({label: e3})
                                })
                                result.push(e1Self);

                            } else if (isFundamentalType(getE1Value)) {
                                result.push({label: getE1Value})
                            } else {
                                let e1Children = [];
                                let e1Self = {label: selfKey, children: e1Children};
                                for (let selfKey2 in getKeyValue1) {
                                    let getKeyValue2 = getKeyValue1[selfKey2];
                                    e1Children.push({label: selfKey2+": "+getKeyValue2})
                                }
                                result.push(e1Self);
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}